package com.lqian.share;

import java.util.ArrayList;
/*volatile并不能保证多个线程共同修改共享变量时所带来的不一致问题，也就是说volatile不能代替synchronized*/
public class T_01 {
    /*volatile*/ int count = 0;

    void m(){
        for (int i = 0; i <10000 ; i++) count++;
    }

    public static void main(String[] args){
        T_01 t = new T_01();

        ArrayList<Thread> threads = new ArrayList<>();

        for (int i = 0; i < 10 ; i++) {
            threads.add(new Thread(t::m,"thread-"+i));
        }

        threads.forEach(o->o.start());
        threads.forEach((o)->{
            try {
                o.join();
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        });
        System.out.println(t.count);
    }


}
